package com.jcl.recruit.console.mapper;

import com.jcl.recruit.console.model.ConsoleDbServer;
import com.jcl.recruit.console.mapper.provider.ConsoleDbServerProvider;
import com.jcl.recruit.mapper.SqlMapper;
import com.jcl.recruit.mapper.provider.SqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface ConsoleDbServerMapper extends SqlMapper {

    String TABLE_NAME = "t_console_db_server";

    @Select({
            SQL_QUERY
    })
    List<ConsoleDbServer> findList();

    @Select({
            SQL_QUERY_PREFIX
    })
    List<ConsoleDbServer> findListByPrefix(@Param("prefix") String prefix);

    @Select({
            SQL_QUERY_ID
    })
    ConsoleDbServer findOne(@Param("id") Integer id);

    @Select({
            SQL_QUERY_SERVER_NAME
    })
    ConsoleDbServer findOneByServerName(@Param("serverName") String serverName);

    @InsertProvider(type = ConsoleDbServerProvider.class, method = SqlProvider.SQL_METHOD_INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(ConsoleDbServer entity);

    @UpdateProvider(type = ConsoleDbServerProvider.class, method = SqlProvider.SQL_METHOD_UPDATE)
    int update(ConsoleDbServer entity);

    String STATUS_0 = "0"; // 可用
    String STATUS_1 = "1"; // 不可用
    String STATUS_2 = "2"; // 弃用
    String SQL_QUERY = "select * from " + TABLE_NAME + " order by id desc ";
    String SQL_QUERY_ID = "select * from " + TABLE_NAME + " where id = #{id}";
    String SQL_QUERY_PREFIX = "select * from " + TABLE_NAME + " where prefix = #{prefix}";
    String SQL_QUERY_SERVER_NAME = "select * from " + TABLE_NAME + " where server_name = #{serverName}";
}
